package com.liuyk.commonlib.dialog;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.liuyk.commonlib.R;

/**
 * 通用弹窗样式，一个标题(左边icon，中间String，右边icon)，一个内容，左右两个按钮，标题和内容之间分割线分割
 * 都可以配置
 * <p>
 * Created by liuyakui on 2019/9/9.
 */
public class CommonDialog extends BaseDialog {
    private ImageView left_icon;
    private ImageView right_icon;

    public CommonDialog(@NonNull Context context) {
        super(context);
        left_icon = findViewById(R.id.left_icon);
        right_icon = findViewById(R.id.right_icon);
        left_icon.setOnClickListener(this);
        right_icon.setOnClickListener(this);
    }

    public void setLeftIcon(int resId) {
        if (resId != -1) {
            left_icon.setImageResource(resId);
            left_icon.setVisibility(View.VISIBLE);
            return;
        }
        left_icon.setVisibility(View.GONE);
    }

    public void setRightIcon(int resId) {
        if (resId != -1) {
            right_icon.setImageResource(resId);
            right_icon.setVisibility(View.VISIBLE);
            return;
        }
        right_icon.setVisibility(View.GONE);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        int id = v.getId();
        if (id == R.id.left_icon) {
        } else if (id == R.id.right_icon) {
            dismiss();
        }
    }

    @Override
    protected int contentView() {
        return R.layout.common_dialog;
    }
}
